Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#e98f36",
    list: [{
      pagePath: "/pages/index/index",
      iconPath: "/images/home.png",
      selectedIconPath: "/images/home_selected.png",
      text: "首页"
    }, {
      pagePath: "/pages/optional/optional",
      iconPath: "/images/optional.png",
      selectedIconPath: "/images/optional_selected.png",
      text: "自选"
    }, {
      pagePath: "/pages/futures/futures",
      iconPath: "/images/spots.png",
      selectedIconPath: "/images/spots_selected.png",
      text: "期货"
    }, {
      pagePath: "/pages/news/news",
      iconPath: "/images/news.png",
      selectedIconPath: "/images/news_selected.png",
      text: "资讯"
    }, {
      pagePath: "/pages/account/account",
      iconPath: "/images/my.png",
      selectedIconPath: "/images/my_selected.png",
      text: "我的"
    }]
  },
  attached() {
  },
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      if (data.index!=4) {
        wx.switchTab({url})
        this.setData({selected: data.index})
      } else {
        let token = wx.getStorageSync('token');
        let tokenExpire = wx.getStorageSync('tokenExpire');
        let currentTime = new Date().getTime();
        if (token) {
          if (currentTime - new Date(tokenExpire).getTime() > 0) {
            // token失效
            wx.redirectTo({
              url: '/packageA/pages/login/index',
            })
          } else {
            wx.switchTab({
              url: '/pages/account/account',
            })
          }
        } else {
          wx.redirectTo({
            url: '/packageA/pages/login/index',
          })
        }
      }
    }
  }
})